package com.example.xy.searchphone;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.xy.searchphone.model.Phone;
import com.example.xy.searchphone.mvp.MvpMainView;
import com.example.xy.searchphone.mvp.impl.MainPresenter;

public class MainActivity extends AppCompatActivity implements View.OnClickListener, MvpMainView {

    EditText input_phone;
    Button btn_search;
    TextView result_phone,
             result_province,
             result_type,
             result_carrier;
    MainPresenter mainPresenter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        input_phone=findViewById(R.id.input_phone);
        btn_search=findViewById(R.id.btn_search);
        result_phone=findViewById(R.id.result_phone);
        result_province=findViewById(R.id.result_province);
        result_type=findViewById(R.id.result_type);
        result_carrier=findViewById(R.id.result_carrier);

        btn_search.setOnClickListener(this);

        mainPresenter = new MainPresenter(this);
        mainPresenter.attach(this);
    }

    @Override
    public void onClick(View view) {
        mainPresenter.searchPhoneInfo(input_phone.getText().toString());
    }


    //mvpMainView
    @Override
    public void showLoading() {

    }

    @Override
    public void hidenLoading() {

    }

    @Override
    public void showToast(String s) {
        Toast.makeText(this,s,Toast.LENGTH_SHORT).show();
    }

    @Override
    public void updateView() {
        Phone phone = mainPresenter.getPhoneInfo();

        result_phone.setText("手机号码:"+phone.getTelString());
        result_province.setText("省份:"+phone.getProvince());
        result_type.setText("运营商:"+phone.getCatName());
        result_carrier.setText("归属运营商:"+phone.getCarrier());
    }
}
